import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";

export const settingSlice = createSlice({
  name: "settings",
  initialState: {
    isCollapse: false,
    tagsViewsStatus: true,
    breadCrumbStatus: true,
    fixedHeaderStatus: false,
    sideThemeStauts: "dark",
    dynamicTitleStatus: false,
    showLogoStatus: true,
    saveSettings: false,
  },
  reducers: {
    // 设置侧边栏状态
    setCollapsed(state, { payload }) {
      state.isCollapse = payload;
    },
    // 设置tags状态
    setTagsViewsStatus(state, { payload }) {
      state.tagsViewsStatus = payload;
    },
    // 设置面包屑状态
    setBreadCrumbStatus(state, { payload }) {
      state.breadCrumbStatus = payload;
    },
    // 设置header状态
    setFixedHeaderStatus(state, { payload }) {
      state.fixedHeaderStatus = payload;
    },
    // 设置侧边栏主题状态
    setSideThemeStatus(state, { payload }) {
      state.sideThemeStauts = payload;
    },
    // 设置动态标题
    setDynamicTitleStatus(state, { payload }) {
      state.dynamicTitleStatus = payload;
    },
    // 显示Logo
    setShowLogoStatus(state, { payload }) {
      state.showLogoStatus = payload;
    },
    // 设置保存配置状态
    setSaveSettings(state, { payload }) {
      if (!payload) {
        state.tagsViewsStatus = true;
        state.breadCrumbStatus = true;
        state.fixedHeaderStatus = false;
        state.sideThemeStauts = "dark";
        state.dynamicTitleStatus = false;
        state.showLogoStatus = true;
      }
      state.saveSettings = payload;
    },
  },
});

export const {
  setCollapsed,
  setTagsViewsStatus,
  setBreadCrumbStatus,
  setFixedHeaderStatus,
  setSideThemeStatus,
  setDynamicTitleStatus,
  setShowLogoStatus,
  setSaveSettings,
} = settingSlice.actions;

export default settingSlice.reducer;
